//package com.zy.config.common;
//
//
//import com.zy.config.feign.PropertyFeign;
//import com.zy.config.utils.RemoteConfigProviderFactory;
//import com.zy.config.utils.RemoteConfigSupport;
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.beans.BeansException;
//import org.springframework.beans.SimpleTypeConverter;
//import org.springframework.beans.factory.BeanFactory;
//import org.springframework.beans.factory.BeanFactoryAware;
//import org.springframework.beans.factory.annotation.Value;
//import org.springframework.beans.factory.config.ConfigurableBeanFactory;
//import org.springframework.context.EnvironmentAware;
//import org.springframework.context.annotation.Configuration;
//import org.springframework.core.env.ConfigurableEnvironment;
//import org.springframework.core.env.Environment;
//
//import javax.annotation.PostConstruct;
//import javax.annotation.Resource;
//import java.io.IOException;
//import java.io.StringReader;
//import java.util.Optional;
//import java.util.Properties;
//
//
//@Slf4j
//@Configuration
//public class BeanAfterService extends RemoteConfigSupport implements BeanFactoryAware, EnvironmentAware {
//
//    private ConfigurableEnvironment environment;
//
//    private ConfigurableBeanFactory beanFactory;
//
//    private SimpleTypeConverter typeConverter;
//
//    private RemoteConfigProviderFactory providerFactory;
//
//    @Resource
//    private PropertyFeign propertyFeign;
//
//    @Value("${spring.application.name}")
//    private String appId;
//
//    private final String CONFIG = "config";
//
//    @PostConstruct
//    public void after() throws IOException {
//        if (!appId.equals(CONFIG)) {
//            String str = propertyFeign.propertyToString(appId);
//            Properties current = new Properties();
//            current.load(new StringReader(str));
//            if (Optional.ofNullable(current).isPresent()) {
//                log.info("开始更新Environment------------------------appId:【{}】",appId);
//                // 更新Environment
//                addPropertySource(this.environment, current);
//                // 更新bean实例的成员变量属性值
//                updateField(beanFactory, environment, typeConverter, current);
//            }
//        }
//    }
//
//
//    @Override
//    public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
//        this.beanFactory = (ConfigurableBeanFactory) beanFactory;
//        this.typeConverter = new SimpleTypeConverter();
//        this.typeConverter.setConversionService(this.beanFactory.getConversionService());
//    }
//
//    @Override
//    public void setEnvironment(Environment environment) {
//        this.environment = (ConfigurableEnvironment) environment;
//        this.providerFactory = new RemoteConfigProviderFactory(this.environment);
//    }
//
//}
//
//
